# FTP Server Error on ftpLib.py

**URL:** <https://forum.inductiveautomation.com/t/ftp-server-error-on-ftplib-py/56651>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [February 28, 2022, 10:07pm UTC](https://forum.inductiveautomation.com/t/ftp-server-error-on-ftplib-py/56651 "2022-02-28T22:07:35Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mandeep\_gill](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@mandeep\_gill](https://forum.inductiveautomation.com/u/mandeep_gill)\
**Post date:** [February 28, 2022, 10:07pm UTC](https://forum.inductiveautomation.com/t/ftp-server-error-on-ftplib-py/56651/1 "2022-02-28T22:07:35Z")

</div>

Hi  
I am currently using ignition version 8.1.14 and OS windows Server 2019.  
I am trying to use the following script which is coming up with Error. I can’t find much information about the ftplib set.What should be the format for the File path or file name. I think script is error due to file path not in correct format.

Following is Script:

```auto
import ftplib
	
# Make sure to include double back slashes. Should be a file path to a folder on the machine this script will run on.

filepath = "D:\\MGILL\WM_20220228_121611.xml"
	
# Check if report exists before trying to upload to FTP server.
file_exists = system.file.fileExists(filepath)
if (file_exists):
	# Connect and login to FTP site
	ftp = ftplib.FTP("ClientFTP")
	ftp.login("Username", "Password") # Username, Password
	ftp_path = "/" # Notice the forward slashes
	ftp.cwd(ftp_path)
	# Can use this to check you are in the proper folder (can comment out after debugging)
	print str(ftp.pwd())
	# Save the file to the FTP site
	ftp.storbinary("STOR " + filepath, open(filepath))
	# Quit the FTP session
	ftp.quit()

```

Error message is

```auto
Traceback (most recent call last):
  File "<event:actionPerformed>", line 22, in <module>
  File "C:\Users\Mg\.ignition\cache\gwlocalhost_8088\C1\pylib\ftplib.py", line 471, in storbinary
    conn = self.transfercmd(cmd, rest)
  File "C:\Users\Mg\.ignition\cache\gwlocalhost_8088\C1\pylib\ftplib.py", line 376, in transfercmd
    return self.ntransfercmd(cmd, rest)[0]
  File "C:\Users\Mg\.ignition\cache\gwlocalhost_8088\C1\pylib\ftplib.py", line 339, in ntransfercmd
    resp = self.sendcmd(cmd)
  File "C:\Users\Mg\.ignition\cache\gwlocalhost_8088\C1\pylib\ftplib.py", line 249, in sendcmd
    return self.getresp()
  File "C:\Users\Mg\.ignition\cache\gwlocalhost_8088\C1\pylib\ftplib.py", line 224, in getresp
    raise error_perm, resp
ftplib.error_perm: 550 The parameter is incorrect. 

Ignition v8.1.14 (b2022012711)
Java: Azul Systems, Inc. 11.0.13

```

---

<div class="post-metadata">

**Author:** ![kcollins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kcollins/32/19646_2.png) [@kcollins](https://forum.inductiveautomation.com/u/kcollins)\
**Post date:** [February 28, 2022, 10:15pm UTC](https://forum.inductiveautomation.com/t/ftp-server-error-on-ftplib-py/56651/2 "2022-02-28T22:15:32Z")

</div>

> [@mandeep\_gill](#):
>
> ```auto
> ftp.storbinary("STOR " + filepath, open(filepath))
> 
> ```

I took a look at the [docs for ftplib](https://docs.python.org/2.7/library/ftplib.html#ftplib.FTP.storbinary) and I'm wondering if you're having problems trying to do `STOR <local system filepath>`. I'm betting that needs to be the path that you're uploading _to_, not the source path. The `fp` object that you're supplying is going to be the local file content.

---

<div class="post-metadata">

**Author:** ![mandeep\_gill](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@mandeep\_gill](https://forum.inductiveautomation.com/u/mandeep_gill)\
**Post date:** [February 28, 2022, 10:36pm UTC](https://forum.inductiveautomation.com/t/ftp-server-error-on-ftplib-py/56651/3 "2022-02-28T22:36:21Z")

</div>

Thanks kcollins for your quick reply.

If i understand you correctly according to Python documentation for FTP.storbinary.  
Command should be STOR with FTP server folder Path?

There is no folder structure inside FTP as systems logon to FTP folder where this file has to be transferred to. I hope it makes sense.

Python documentation:  
`FTP.` `storbinary` ( _command_ , _fp_ [, _blocksize_ , _callback_ , _rest_])

Store a file in binary transfer mode. _command_ should be an appropriate `STOR` command: `"STOR filename"` . _fp_ is an open file object which is read until EOF using its `read()` method in blocks of size _blocksize_ to provide the data to be stored. The _blocksize_ argument defaults to 8192. _callback_ is an optional single parameter callable that is called on each block of data after it is sent. _rest_ means the same thing as in the [`transfercmd()`](https://docs.python.org/2.7/library/ftplib.html#ftplib.FTP.transfercmd) method.

Changed in version 2.1: default for _blocksize_ added.

Changed in version 2.6: _callback_ parameter added.

Changed in version 2.7: _rest_ parameter added.

---

<div class="post-metadata">

**Author:** ![kcollins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kcollins/32/19646_2.png) [@kcollins](https://forum.inductiveautomation.com/u/kcollins)\
**Post date:** [February 28, 2022, 10:58pm UTC](https://forum.inductiveautomation.com/t/ftp-server-error-on-ftplib-py/56651/4 "2022-02-28T22:58:24Z")

</div>

In that case I’d try just using the base name of the file… The following might be useful to integrate into your script:

```python
import os
filepath="C:\\path\\to\\file.txt"
print("Base name is '%s'" % os.path.basename(filepath))

```

The above, when run on Windows (and thusly understand the Windows-based file path separators, etc), will output `file.txt` as the base name, which you could use as the filename for the FTP remote (since you mention that you’re already going to be logged into the target path).

---

<div class="post-metadata">

**Author:** ![mandeep\_gill](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@mandeep\_gill](https://forum.inductiveautomation.com/u/mandeep_gill)\
**Post date:** [March 1, 2022, 9:01pm UTC](https://forum.inductiveautomation.com/t/ftp-server-error-on-ftplib-py/56651/5 "2022-03-01T21:01:27Z")

</div>

Thanks kcollins,  
I have tried your suggestion, It didn’t work for me.  
I did search few other things pointing to file path.  
It appears that script is adding additional slash \ and complaining about path not found.

Noticed message is still displaying two slashes as one. Not sure why

Now i am getting error .  
IOError: (2, ‘No such file or directory’, ‘D:\MGILL\Water\WM\_20220228\_121611.xml’)

---

<div class="post-metadata">

**Author:** ![kcollins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kcollins/32/19646_2.png) [@kcollins](https://forum.inductiveautomation.com/u/kcollins)\
**Post date:** [March 1, 2022, 9:25pm UTC](https://forum.inductiveautomation.com/t/ftp-server-error-on-ftplib-py/56651/6 "2022-03-01T21:25:28Z")

</div>

It seems like there is an issue opening the file… Does that file exist in the scope (gateway or client/designer) that you’re running the script from? Note that if you’re running in the script console, it will be looking for the file on the computer you’re running the Designer from, not the gateway…

---

<div class="post-metadata">

**Author:** ![mandeep\_gill](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@mandeep\_gill](https://forum.inductiveautomation.com/u/mandeep_gill)\
**Post date:** [March 1, 2022, 11:11pm UTC](https://forum.inductiveautomation.com/t/ftp-server-error-on-ftplib-py/56651/7 "2022-03-01T23:11:38Z")

</div>

Currently i am running the script which is button action.  
I am running client on the ignition gateway where this file is stored locally on D Drive.

---

<div class="post-metadata">

**Author:** ![mandeep\_gill](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@mandeep\_gill](https://forum.inductiveautomation.com/u/mandeep_gill)\
**Post date:** [March 2, 2022, 1:37am UTC](https://forum.inductiveautomation.com/t/ftp-server-error-on-ftplib-py/56651/8 "2022-03-02T01:37:42Z")

</div>

Hi kcollins  
I manage to solve the issue by removing the file from folder and just put into D drive. from there file transfer does work. I will later put the script code for other’s reference.

---

<div class="post-metadata">

**Author:** ![mandeep\_gill](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@mandeep\_gill](https://forum.inductiveautomation.com/u/mandeep_gill)\
**Post date:** [March 2, 2022, 6:32pm UTC](https://forum.inductiveautomation.com/t/ftp-server-error-on-ftplib-py/56651/9 "2022-03-02T18:32:32Z")

</div>

Hi Guys,  
Later i noticed as pointed by others . If the script is running on gateway then you have to check if folder have premissions to read and write.

If the script is running on client with windows login which have premission to access all the folder with read and write then you won’t see the issue which is highlighted above. Final script which work on client is as follow. I still got same issue when run from gateway.

```auto
import ftplib
# Make sure to include double back slashes.
FTPfilepath = ('C:\\Folder\WM_'+ string2xmlFile + '.xml') #File path is concatenate with location and Datetime stamp
filename = ('WM_' + string2xmlFile + '.xml') # File name is concatenate name and Datetime stamp
file_object = open(os.path.realpath(FTPfilepath), 'rb')
# Check if report exists before trying to upload to FTP server.
file_exists = system.file.fileExists(FTPfilepath)
if (file_exists):
	# Connect and login to FTP site
	print('Connecting to FTP Server')
	ftp = ftplib.FTP("client")
	ftp.login("username", "password") # Username, Password
	# Navigate to folder on the FTP site you want to save the file to.
	ftp_path = "/" # Notice the forward slashes
	ftp.cwd(ftp_path)
	# Can use this to check you are in the proper folder (can comment out after debugging)
	print str(ftp.pwd())
	# Save the file to the FTP site
	print('Storing File to FTP server')
	ftp.storbinary('STOR ' + filename, file_object)
	print('File Stored to FTP server')
	# Close File Object
	file_object.close()
	# Quit the FTP session
	ftp.quit()

```

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [March 10, 2022, 11:42am UTC](https://forum.inductiveautomation.com/t/ftp-server-error-on-ftplib-py/56651/10 "2022-03-10T11:42:09Z")

</div>

Can you edit and apply code formatting to your code? Select the text and hit the `</>` code formatting button. As it is all the indentation is lost. You’ll also get syntax highlighting for free! Thanks.
