Created
June 16, 2022 12:07
-
-
Save pmandreoli/5e361632b4956b6b272d9ea33f495bac to your computer and use it in GitHub Desktop.
ftp test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
from ftplib import FTP | |
import argparse | |
################################################################################ | |
# COMMAND LINE OPTIONS | |
def cli_options(): | |
parser = argparse.ArgumentParser(description='Galaxy URL upload and FastQC test') | |
parser.add_argument('--ip', dest='FtpIp', default='localhost', help='proftp url') | |
parser.add_argument('--file', dest='FPath', help='File to transfer') | |
parser.add_argument('--user', dest='User', help="ftp username") | |
parser.add_argument('--password', dest='Passwd', help="user passwd") | |
return parser.parse_args() | |
def ftp_login(host, user, passwd): | |
test = FTP(host=host,user=user,passwd=passwd ) | |
return test | |
def ftp_upload(test,file_path): | |
file = open(file_path,'rb') | |
try: | |
fname = file_path[file_path.rfind('/')+1:] | |
print(fname) | |
except: | |
fname = file | |
test.storbinary(f'STOR {fname}', file) | |
file.close() | |
if __name__ == '__main__': | |
options = cli_options() | |
test = ftp_login(host=options.FtpIp, user=options.User, passwd=options.Passwd) | |
ftp_upload(test=test,file_path=options.FPath) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment