Python Forum

Full Version: file transfer via python SFTP SCP
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi Team,

I am transfering csv files to cloud via SFTM transfer.
below code is works when i use subprocess.Popen


but doesnt work if i use run command.
subprocess.run(['scp',fname,landing_path])

i am using windows.

def File_transfer(fpath,tbl)

	
	import subprocess
	import os
	
	fname = os.path.join(fpath,tbl)
	landing_path = '"I:\\Test_cloud.txt",[email protected]://disk4//app/landing'	
	subprocess.Popen(['scp',fname,landing_path])


	

if __name__ == "__main__":
	fpath = "D:\\Reports"
	tbl = "Table1.zip"
(Sep-10-2022, 04:36 AM)mg24 Wrote: [ -> ]but doesnt work if i use run command. subprocess.run(...
In the code shown above, you are not using subprocess.run() but subprocess.Popen(), also the File_transfer() function is never called. Also « it doesn't work » is not a usable error report. Describe what happens when you run the code, and all output.
Also should get syntax error on line 1 as missing :.
Import statement should be on top of code.
Here a working test for upload with scp from Windows to our Linux server.
import subprocess
import os

def file_transfer(fpath, tbl):
    fname = os.path.join(fpath, tbl)
    landing_path = "[email protected]:/var/www/python-forum.io/images/tips"
    subprocess.run(['scp', '-P', '2xxx', fname, landing_path])

if __name__ == "__main__":
    # On server from Win to Linux Path is like this
    # G:\1_bilder\logo\speed.png
    fpath = "/G/1_bilder/logo/"
    tbl = "speed.png"
    file_transfer(fpath, tbl)
Hi Team,

Here a working test for upload with scp from Windows to our Linux server.

What changes to make to transfer files if its windows to windows server. in below code
subprocess.run(['scp', '-P', '2xxx', fname, landing_path])