Page 1 of 1

FTP - Upload Only New Files - Ftp script to upload only file

Posted: 08 Sep 2010 11:47
by pradeep
Hi,

i was trying to do something with file

FTP - Upload Only New Files - Ftp script to upload only files that don`t exist in remote folder, i.e. incremental upload

given on this site.

and now getting error like :The input line is too long.

can anyone help me out how i can get rid of that.

thanks looking for quick response.

Re: FTP - Upload Only New Files - Ftp script to upload only

Posted: 08 Sep 2010 18:58
by ghostmachine4
pradeep wrote:Hi,

i was trying to do something with file

FTP - Upload Only New Files - Ftp script to upload only files that don`t exist in remote folder, i.e. incremental upload

given on this site.

and now getting error like :The input line is too long.

can anyone help me out how i can get rid of that.

thanks looking for quick response.



that long batch file has a limit. Please read the part on "Note:" . If you can afford to, use a programming language that has good ftp libraries, eg Python( or Perl). Here's a Python script you can try

Code: Select all

import ftplib
host="localhost"
username="anonymous"
password="asdfasf"
file_to_upload="file"
def upload(ftp, filename):
    ftp.storbinary("STOR " + filename, open(filename, "rb"), 1024)
try:
    ftp = ftplib.FTP(host)
    ftp.login(username, password)
except Exception,e:
   print e
else:
   filelist=[]
   ftp.retrlines('LIST',filelist.append)
   if file_to_upload not in filelist:
       file = open(file_to_upload, "rb")
       print 'STORing File now...'
       upload(ftp,file_to_upload)
   ftp.quit()
   file.close()



save as myftp.py, and on command line

Code: Select all

c:\test> python myftp.py



Advantages:
1) Don't have to connect to FTP server several times
2) Lesser and easier to read/maintain code.
3) Works in Windows as well as *nix (cross platform) with little or no modification.
4) no need to maintain extra FTP script.
5) no need to create intermediate files.
6) more efficient than the batch, since no extra calls to external commands using pipes.