Tuesday, March 1, 2011

[share] python script for uploading file via ftp


Okay, my friends, see you again. Today i will share to you the simple python script for uploading file via ftp (file transfer protocol). This script is very simple and tiny file. Just Copy and paste this script to your notepad or text editor, and edit with your ftp server address, username and password, after that just save with *.py in case i save it with ftp.py name.
Okay so let me show you the script,
 
#!/usr/bin/python 
# usage: python ftp.py filename

import os,sys
from ftplib import FTP

server = 'ftp.domain-example.com'
username = 'your-username'
passwd = 'your-pass'
filename = sys.argv[1]
ftp = FTP(server)
ftp.login(username,passwd)
fp = open(filename, 'rb')
ftp.storbinary("STOR "+filename, fp)
ftp.quit()

for use it just type on your command line (terminal) with this command :
$python ftp.py filename
Change "filename" with your filename that you want to upload it to your server.
Its DONE!

0 comments:

Post a Comment

 

About Me

My Photo
just4shareIT
Just4ShareIT is my way to share what i know and what i did.Hope u can get somethings from my notes on this blog..
View my complete profile

Statistic

free counters Ping your blog, website, or RSS feed for Free Free web Counter Log Counter powered by  http://www.myusersonline.com

Followers

Just4shareIT Copyright © 2011 | Powered by Blogger