55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
|
|
#!/usr/bin/python3
|
||
|
|
|
||
|
|
import ftplib
|
||
|
|
|
||
|
|
#session = ftplib.FTP('hoschis-tippspiel.de','w0172dd3','DyhrkJaf3NMY')
|
||
|
|
#session = ftplib.FTP('programmschmiede.de','w00c9c8c','qreny52h')
|
||
|
|
#file = open('upload_test.py','rb') # file to send
|
||
|
|
#session.storbinary('STOR upload_test.py', file) # send the file
|
||
|
|
#file.close() # close file and FTP
|
||
|
|
#session.quit()
|
||
|
|
|
||
|
|
import os.path, os
|
||
|
|
from ftplib import FTP, error_perm
|
||
|
|
|
||
|
|
host = 'programmschmiede.de'
|
||
|
|
port = 21
|
||
|
|
user = "w00c9c8c"
|
||
|
|
password = "qreny52h"
|
||
|
|
|
||
|
|
ftp = FTP()
|
||
|
|
ftp.connect(host,port)
|
||
|
|
ftp.login(user,password)
|
||
|
|
ftp.cwd("pfosten")
|
||
|
|
filenameCV = "../pfosten"
|
||
|
|
|
||
|
|
|
||
|
|
def placeFiles(ftp, path):
|
||
|
|
for name in os.listdir(path):
|
||
|
|
localpath = os.path.join(path, name)
|
||
|
|
if os.path.isfile(localpath):
|
||
|
|
print("STOR", name, localpath)
|
||
|
|
ftp.storbinary('STOR ' + name, open(localpath,'rb'))
|
||
|
|
#print("name:",name)
|
||
|
|
#print("Localpath:",localpath)
|
||
|
|
elif os.path.isdir(localpath):
|
||
|
|
#print("MKD", name)
|
||
|
|
|
||
|
|
try:
|
||
|
|
ftp.mkd(name)
|
||
|
|
|
||
|
|
# ignore "directory already exists"
|
||
|
|
except error_perm as e:
|
||
|
|
if not e.args[0].startswith('550'):
|
||
|
|
raise
|
||
|
|
|
||
|
|
#print("CWD", name)
|
||
|
|
ftp.cwd(name)
|
||
|
|
placeFiles(ftp, localpath)
|
||
|
|
#print("CWD", "..")
|
||
|
|
ftp.cwd("..")
|
||
|
|
|
||
|
|
placeFiles(ftp, filenameCV)
|
||
|
|
|
||
|
|
ftp.quit()
|