Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shell FTP Upload w/ Error Checking 1

Status
Not open for further replies.

acl03

MIS
Jun 13, 2005
1,077
US
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):

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

[medal] Hard work often pays off over time, but procrastination pays off right now!
 
Thanks for that link. Checking the FTP.exe output file is an easy error-checking mechanism.

Thanks,
Andrew

[medal] Hard work often pays off over time, but procrastination pays off right now!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top