DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

FTPDownload DIAdem 2017 FileSize is 0kB w/o FTP Error

Hi,

 

I wrote a little script:to download an ASCII file (4kB) (see below) and I always retrieving an empty file (0kB). With FileZilla I don't have any issues.

Any advises? (Encoding / FTPClient)

 

Tx

Thomas

 

DataReadPath ="X:\Dokumentation\Energiverbrauch"
Const sFTPServerAddress = "10.111.111.xx"
Const sUser = "user"
Const sPW = "passwort"
Const sDownloadDir = "/usr/sicx/mount/os1/data/cpm/ap/"
Const sFuelFile = "TEXTFILE.txt"

 

Sub btnDownloadFile_EventClick(ByRef This) 'Erzeugter Event-Handler
Dim conState, dlState
    conState = ConnectToFTP(sFTPServerAddress, sUser ,sPW)
    If conState > 0 Then
      txtFTPPath.ForeColor = VBGreen
      txtFTPPath.Text = sDownloadDir & sFuelFile
      dlState = DownLoadFuelData(conState, sDownloadDir, sFuelFile, DataReadPath)
      Select Case dlState
        Case "FTPNoError"
        btnLoadFile.Enable = true
        OK.Enable = true
          Call MsgBox("Download completed")
        Case "FTPError"
          Call MsgBox("An error occured")
        Case "FTPTimeout"
          Call MsgBox ("Timeout")
        Case "FTPAbort"
          Call MsgBox ("Cancel")
      End Select    
    Else
      txtFTPPath.ForeColor = VBRed
      txtFTPPath.Text = "Could not connect to the server."
    End If
    Call FTPDisconnect(conState)
End Sub
Function ConnectToFTP(ipAddress, user, pw)
Dim conState
    conState =  FTPConnect(ipAddress, user, pw)
    ConnectToFTP = conState
End Function
Function DownLoadFuelData(oConnectionState, sSourceDir, sFileName, sTargetDir)
Dim oDownloadState
    If oConnectionState > 0 Then
    'Call MsgBox(sTargetDir  & " " & sFileName)
    Call LogFileWrite("Handle: " & oConnectionState & " SourcePath: " & sSourceDir & sFileName & " TargetDir: " & sTargetDir)
      oDownloadState = FTPDownload(oConnectionState, sSourceDir, sFileName,  sTargetDir)       
      
    Else
      Call MsgBox("Could not connect to the server.")
    End If
    DownLoadFuelData = oDownloadState
End Function

 

0 Kudos
Message 1 of 3
(2,624 Views)

I found the problem. It's an encoding issue. The ASCII file contains "NAK, Negative Acknowledge" sign.

Is there a way to add maybe a hidden parameter to the FTPClient?

 

BR

 

Thomas

0 Kudos
Message 2 of 3
(2,579 Views)

Potentially it is easier to use the shell methods instead.

Option Explicit

dim user : user = ""
dim pwd : pwd = ""
dim path : path = "ftp://" & user & ":" & pwd & "@ftp.ni.com/README.txt"
dim targetpath : targetPath = "C:\temp"

dim oShell : Set oShell = CreateObject("Shell.Application")
dim oftp : set oFtp = oShell.NameSpace(path)

dim targetFolder : set targetFolder = oShell.NameSpace(targetPath)
call targetFolder.CopyHere(oftp)

which just uses Windows Explorer functionallity. In this case binary is the default. The CopyHere can be configured to supress the dialog.

0 Kudos
Message 3 of 3
(2,571 Views)