Hi all,
I am trying to write a script that will zip a file and upload it to an FTP site. I have it working, but I want to add error checking on the FTP portion to veify that the file was actually uploaded.
Here is how I am doing the FTP portion (there are some references to Variables & Functions that are not present in this code snippet):
I tried changing some things that would cause the FTP to not work (using bad credentials, bad folder name, taking away permissions on the server). This doesn't seem to capture any FTP errors in the "errors" variable on the last line. I guess that is because the FTP program itself did not error out, the stuff running inside it had errors.
Any simple way to just see if the file exists on the server, and maybe compare the file sizes to determine if they are the same?
Thanks,
Andrew
Hard work often pays off over time, but procrastination pays off right now!
I am trying to write a script that will zip a file and upload it to an FTP site. I have it working, but I want to add error checking on the FTP portion to veify that the file was actually uploaded.
Here is how I am doing the FTP portion (there are some references to Variables & Functions that are not present in this code snippet):
Code:
'Create text file for ftp upload
ftpFilename = "ftp.txt"
ftpServer = "10.0.0.1"
ftpUser = "username"
ftpPassword = "pw"
ftpFolder = "folderName"
ftpFileOutput = "open " & ftpServer & vbCrLf & ftpUser & vbCrLf & ftpPassword & vbCrLf & "cd " & ftpFolder & vbCrLf & "put " & zipFileName & vbCrlf & "quit"
Set objTextFile = objFSO.OpenTextFile (workingDir & ftpFilename, ForWriting, True)
errors = objTextFile.WriteLine(ftpFileOutput)
objTextFile.Close
Set objTextFile = Nothing
If errors = 0 Then
logOutput = logOutput & getLogHeader & workingDir & ftpFilename & " created successfully."
Else
logOutput = logOutput & getLogHeader & "Error creating" & workingDir & ftpFilename & "!"
End If
'Send file via ftp
ftpCmd = "ftp.exe -s:" & workingDir & ftpFilename
logOutput = logOutput & getLogHeader & "Starting FTP Upload to " & ftpServer & "."
errors = oShell.Run (ftpCmd, 0, 1)
I tried changing some things that would cause the FTP to not work (using bad credentials, bad folder name, taking away permissions on the server). This doesn't seem to capture any FTP errors in the "errors" variable on the last line. I guess that is because the FTP program itself did not error out, the stuff running inside it had errors.
Any simple way to just see if the file exists on the server, and maybe compare the file sizes to determine if they are the same?
Thanks,
Andrew
Hard work often pays off over time, but procrastination pays off right now!