Alteryx designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.
SOLVED

Delete file from SFTP

Highlighted
Alteryx
Alteryx

Hi @djodts , 

 

Here is an example workflow that deletes files from an SFTP using a combo of the Download & Python tools. The example should be pretty straightforward, you just need to plug in your SFTP info in the necessary places (the red Comment boxes indicate tools that need to be updated). 

 

Please let me know if you have questions, happy to help. 

 

Unfortunately, as others have already pointed out, the Delete function in the download tool is not the same Delete function used against an FTP server.  

 

Best, 


Eric McGilliard

Highlighted
Asteroid

Thanks @EricM 

 

I was able to make some edits to get my files up since I am working with PDFs and don't need to parse dates so.  I also updated the Python tool as directed with my credentials ftp site as well as the URL field so it knew exactly which folder these files are in to delete.  I attached some screenshots, so please advise if I am overlooking something.  Thank you!

Alteryx
Alteryx

@djodts

 

The ftps.cwd (current working directory) statement is only used for navigating to sub-folders within the SFTP, which means it is optional and my not be needed in your case.  

 

Let's say you have a subfolder in your SFTP named "PDF_FOLDER", which contained the pdf files you want to delete.  In that case, you would navigate to the folder with the ftps.cwd statement, like this: 

 

ftps.cwd('PDF_FOLDER')

 

Once you are working in the correct directory, the FOR loop in the next statement will pass the list of filenames within that directory to be deleted. 

 

Hope that helps, let me know if you have any other questions. 

Highlighted
Asteroid

@EricM 

 

Thanks.  I do need the subfolder to be identified in this case so I updated it, but I am still seeing a handful of errors in the Python app that I'm not sure how to correct.  Any suggestions on how to troubleshoot?  I attached a screenshot but am not knowledgeable about Python to figure out.

Highlighted
Alteryx
Alteryx

Hi @djodts

 

Here are some basic troubleshooting tips: 

  1.  First run the workflow with some test data (Perhaps put a test pdf in your SFTP directory).
  2.  Open the Python tool and run each cell (Ctrl+Enter), one at a time. This will make it a bit easier to debug.  You need          to run each cell in the Notebook in order (top to bottom).  If you change a variable, you always need to rerun the cell
  3.  Make sure you've set the variables correctly: 

           user = 'Username'
           pw = 'Password'
           ftp = 'upload.testftp.com'

           ftps.cwd = 'DirectoryName'

 

Edit - One more thing to check, the data flowing into the Python tool should have a field name Filename, which is the list of files to be deleted.  

 

I have added a screenshot below that shows what the output should be for each cell.  

 

 

EricM_0-1572283421119.png

 

Highlighted
Asteroid

@EricM 

 

Thanks for the continued help.  I did check everything and believe my Python tool matches yours verbatim (of course with my credentials instead of the generic ones) but still have the same error.  I did notice one thing.  I am trying to connect to an SFTP not FTPS.  Your configuration seems to reference "ftps" which normally wouldn't be an issue since it's just a label but am wondering if the first cell which calls the "FTP_TLS" should be configured differently?  I'm certainly no FTP expert, but from what I understand, TLS is associated with FTPS, not necessarily SFTP?  Hoping I'm onto something

Labels