ftp automation

ScriptFTP

The professional tool to automate FTP, SFTP, FTPS and schedule FTP batch jobs

The forum is now read only. Please, go to the the main ScriptFTP website if you need help.
Post here if you experience file transfer problems or unexpected errors.
I have a problem with the UPLOAD function of SYNC. The ftp server I am connecting to is running on MSDOS and will not accept the long filenames with the .part added extension. (this is what I deduct from the server output with default SETUPLOADMODE)

When switching to DIRECT UPLOADMODE it tries to overwrite the file with the direct filename, but then it sounds: error: File already exists.

Here is the feeback (VERBOSE(ON))
Default "SETUPLOADMODE":
SYNC("D:\BCS\Datafms\rcp","/rcp",UPLOAD)
CWD /rcp
250 CWD command successful
PWD
257 "/RCP/" is current directory
Clock time difference is -31600776 seconds.
Synchronizing remote directory /rcp from D:\BCS\Datafms\rcp. Ignoring subdirectories.
PASV
227 Entering Passive Mode (10,45,16,66,9,231)
Opening data connection to 10.45.16.66 Port: 2535
LIST
150 Sending file list
1078 bytes transferred. (13.4 KB/s) (78 ms)
226 Transfer complete
MDTM 1.RCP
213 20050524001100
Remote file time: 05/24/2005 00:11:00
Adjusted remote file time: 05/24/2006 18:10:36
Local file time: 02/28/2013 10:47:02

Uploading (remote file is older) 1.RCP
DELE 1.RCP.part
550 Bad file
PASV
227 Entering Passive Mode (10,45,16,66,9,29)
Opening data connection to 10.45.16.66 Port: 2333
STOR 1.RCP.part
550 Bad path

***** SYNC Error #17550: Cannot upload local file 1.RCP.
***** The server said: Bad path

SETUPLOADMODE(DIRECT)

SYNC("D:\BCS\Datafms\rcp","/rcp",UPLOAD)
CWD /rcp
250 CWD command successful
PWD
257 "/RCP/" is current directory

Clock time difference is -31600776 seconds.
Synchronizing remote directory /rcp from D:\BCS\Datafms\rcp. Ignoring subdirectories.
PASV
227 Entering Passive Mode (10,45,16,66,8,125)
Opening data connection to 10.45.16.66 Port: 2173
LIST
150 Sending file list
1078 bytes transferred. (13.4 KB/s) (78 ms)
226 Transfer complete
MDTM 1.RCP
213 20050524001100
Remote file time: 05/24/2005 00:11:00
Adjusted remote file time: 05/24/2006 18:10:36
Local file time: 02/28/2013 10:47:02

Uploading (remote file is older) 1.RCP
PASV
227 Entering Passive Mode (10,45,16,66,9,219)
Opening data connection to 10.45.16.66 Port: 2523
STOR 1.RCP
553 File exists already

***** SYNC Error #17553: Cannot upload local file 1.RCP.
***** The server said: File exists already
I am now considering to bypass this by using the below code, but I would prefer SYNC:

[ScriptFTP]GETLIST
GETFILETIME(LOCAL)
GETFILETIME(REMOTE)
IF $BLA > $BLABLA
DELETEFILE
PUTFILE
END IF[/ScriptFTP]

Thank you for your advice!
Jonas
Hello Jonas,

Thanks for posting here. I modified the script you posted but I think it will not work as good as SYNC. The problem is that it does not handle the clock time difference that may exist between the the computer where ScriptFTP is running and the FTP server.
FTP Script
  1. # Get the file listing
  2.  
  3. GETLIST($list,LOCAL_FILES)
  4.  
  5. # For each remote file
  6.  
  7. FOREACH $file IN $list
  8.     $localfile_time = GETFILETIME(LOCAL,$file)
  9.     $remotefile_time = GETFILETIME(REMOTE,$file)
  10.     IF($localfile_time > $remotefile_time)
  11.         DELETEFILE($file)
  12.         PUTFILE($file)
  13.     END IF
Another way that might work is comparing the file sizes. If you are sure that in your case a newer file always implies a different file size you can use this one:
FTP Script
  1. # Get the file listing
  2.  
  3. GETLIST($list,LOCAL_FILES)
  4.  
  5. # For each remote file
  6.  
  7. FOREACH $file IN $list
  8.     $localfile_size = GETFILESIZE(LOCAL,$file)
  9.     $remotefile_size = GETFILESIZE(REMOTE,$file)
  10.     IF($localfile_size != $remotefile_size)
  11.         DELETEFILE($file)
  12.         PUTFILE($file)
  13.     END IF
I noticed the problem of time difference indeed. I fixed it by making a timesync, but is is only 99%.

I will let it run on filesize for a while to see where it goes.

EDIT: The FTP server won't accept the SIZE command, so I am back to the time for now. The fault is with the ftp server.

Thanks!
Jonas
Thanks for the update Jonas