Python Forum
file transfer via python SFTP SCP
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
file transfer via python SFTP SCP
#1
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"
Yoriz write Sep-10-2022, 06:42 AM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
(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.
Reply
#3
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)
Reply
#4
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])
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  no such file or directory in SFTP saisankalpj 2 1,564 Nov-25-2022, 11:07 AM
Last Post: DeaD_EyE
  python transfer Sql table to csv using BCP mg24 2 1,384 Oct-04-2022, 06:54 AM
Last Post: mg24
  Multithreaded file transfer from multiple volumes skoobi 2 1,150 Jul-28-2022, 07:52 AM
Last Post: skoobi
Question resume file transfer onran 0 1,643 Jan-27-2021, 02:16 PM
Last Post: onran
  Remote File Transfer- Error wonderboy 1 1,684 Jan-06-2021, 11:24 AM
Last Post: wonderboy
  code to read files in folders and transfer the file name, type, date created to excel Divya577 0 1,870 Dec-06-2020, 04:14 PM
Last Post: Divya577
  DNP3 file transfer with python Aussie 0 1,460 Sep-01-2020, 10:45 PM
Last Post: Aussie
  Splitting the audio file into smaller packets before transfer using UDP protocol in p MuhammadAli152 0 3,739 May-15-2020, 03:01 PM
Last Post: MuhammadAli152
  Opening CSV file from SFTP server not working cluelessintern 0 2,780 Apr-08-2020, 08:10 PM
Last Post: cluelessintern
  How to stop Xmodem after bin file transfer was finished shaya2103 0 2,518 Nov-27-2019, 04:33 PM
Last Post: shaya2103

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020