Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import ftplib
- import sys
- if __name__ == "__main__":
- ipaddress = sys.argv[1]
- filename = sys.argv[2]
- filepathDestination = sys.argv[3]
- user = sys.argv[4]
- password = sys.argv[5]
- obj = filetransfer(ipaddress)
- value = obj.ftpPush()
- if value == True:
- ftp = ftplib.FTP(ipaddress)
- ftp.login(username = user,passwd = password)
- ext = os.path.splitext(filename)[1]
- if ext in (".txt"):
- ftp.cwd(filepathDestination)
- ftp.storlines("STOR " + filename, open(filename))
- else:
- ftp.storbinary("STOR " + filename, open(filename, "rb"), 1024)
- else:
- print 'Wrong IP'
- Traceback (most recent call last):
- File "ftp.py", line 35, in <module>
- ftp = ftplib.FTP(ipaddress)
- File "/usr/lib64/python2.6/ftplib.py", line 116, in __init__
- self.connect(host)
- File "/usr/lib64/python2.6/ftplib.py", line 131, in connect
- self.sock = socket.create_connection((self.host, self.port), self.timeout)
- File "/usr/lib64/python2.6/socket.py", line 567, in create_connection
- raise error, msg
- socket.error: [Errno 111] Connection refused
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement