I assumed that you would like to download all files and all folders from the FTP server.
In Python, you can use the ftplib library.
The code looks like this:
import ftplib import os local_path = [] ftp = ftplib.FTP("FTP Server") ftp.login("username","password") ## Function ### def downloadfiles(directory): global local_path print("Download files from ",directory) if directory!='.': local_path.append(directory) if(len(local_path) != 0): joined_str = "\\".join(local_path) if os.path.exists(joined_str) == False: print("Create a local directory ", joined_str) os.makedirs(joined_str) ftp.cwd(directory) for name, facts in ftp.mlsd(): if(facts["type"] == 'dir'): downloadfiles(name) if(facts["type"] == 'file'): print("Download a file ", name) ftp.retrbinary("RETR "+name, open(joined_str+"\\"+name, 'wb').write) if len(local_path) != 0: local_path.pop() if ftp.pwd() != '/': ftp.cwd("..") ## End Function ## downloadfiles(".") ftp.close()
This is just a sample code. Please test it thoroughly before using it in production.
Hi @Jirapongse ,
I want to try to pull all files from FTP via VBA.
Can you please help me with this error
Hi @Jirapongse ,
Thanks a lot for the above FTP command.
I tried connecting same with VBA.
\
But not able to rectify error, Can you please help me
I can run it properly. You need to create a python file (.py), not a notebook file (.ipynb).
Sub RunPythonScript() Dim objShell As Object Dim PythonExePath, PythonScriptPath As String Set objShell = VBA.CreateObject("Wscript.Shell") PythonExePath = """C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\Python.exe""" PythonScriptPath = """C:\D_DRIVE\hello.py""" objShell.Run PythonExePath & PythonScriptPath End Sub