Solved

How to transfer files to a server via FTP from the Qapp?

  • 28 October 2021
  • 1 reply
  • 245 views

Userlevel 2
Badge +1

I would like to FTP the files that are generated by my qapp to a local server. 

icon

Best answer by pradeep.gaddameedi 28 October 2021, 12:40

View original

1 reply

Userlevel 2
Badge

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. 

  1. 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. 
  2. Now covert this string into file like object. (because you can only transfer a file object to an FTP server)
  3. 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


Community |  Ideas

Facebook |  Instagram |  Youtube |  Twitter |  LinkedIn
Privacy & Security Statement  |  Terms & Conditions |  Impressum  |  UK Modern Slavery Statement