I would like to FTP the files that are generated by my qapp to a local server.
Page 1 / 1
Hi Rakesh, I think you want to upload an output csv file from Qapp to an FTP server.
There is no straight forward approach in Qapp for this. You can follow below approach to save Qapp output in JSON format, CSV format or any other text format.
- Convert the required data into a string. For example, if you want the output text file to be in CSV then convert the required output info into a multiline string with comma separated columns.
- Now covert this string into file like object. (because you can only transfer a file object to an FTP server)
- Use ftplib python library to transfer this file like object to FTP server.
Sample Code in Qapp:
from ftplib import FTP
import io
csvString = """
Col1,Col2\n
Data11,Data12\n
Data21,Data22
"""
byteString = bytes(csvString, 'utf-8')
fileObj = io.BytesIO(byteString)
ftp = FTP('10.10.0.1') #FTP server Name or IP address
ftp.login(user='ftpuser', passwd = 'password') #FTP server login credentials
ftp.storbinary("STOR TestFile.csv",fileObj) #File Object will be stored as a file.
ftp.quit()
Note: FTP ports should be opened for source IP of NetBrain worker server destined to FTP server.
Reply
Login to the community
No account yet? Create an account
Sign in with SSO
Login via NetBrain Universityor
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.