Hi, is it possible to change the working directory more than once during the same SFTP connection? I just want to make sure, as I'm getting an error.
What I'm doing is uploading files to websites in an Excel file:
1. Open SFTP Connection
2. Open Excel file with URLs
3. Start Loop (through all URLs in Excel file)
4. Read URL from LoopIndex row and store in %URL%
5. Change working directory in SFTP connection to folder %URL%
6. Upload files
7. End loop
8. Close Excel
9. Close SFTP Connection
The first time it loops, it changes the working directory fine, and uploads the files. But the second time, it always gives an error: "Cannot change working directory to...".
I know that the file paths are correct, because if I open and close the SFTP connection each time it loops, there is no error. For example, this loop works fine:
Start Loop (through all URLs in Excel file)
Open SFTP Connection
Read URL from LoopIndex row and store in %URL%
Change working directory in SFTP connection to folder %URL%
Upload files
Close SFTP Connection
End loop
So it seems that a new SFTP connection needs to be made each time I want to change the directory. Is this correct?


Hello there! First, let me give you a direct answer: no, this is not correct: you do not have to create a new SFTP connection every time. Let me get in a little more detail about the "Change Working Directory" action:
When you use the specific action it always changes the directory relative to the directory that you are currently in. This is a pretty fundamental behavior of an FTP server and if the action was changing the directory based on the initial directory, it would cause even more confusion.
For example, if you had a folder structure like the following:
root dir
-- Sub Folder 1
-- Sub Folder 2
---- XSub Folder 1
------ EXSub Folder 1
------ EXSub Folder 2
---- XSub Folder 2
and you wanted to copy some files to "Sub Folder 2", "XSub Folder 1" and "EXSub Folder 2", all you have to do is the following:
Change Working Directory "Sub Folder 2"
Copy Files
Change Working Directory "XSub Folder 1"
Copy Files
Change Working Directory "EXSub Folder 2"
Copy Files
Below you can find an example:
Let's assume that you have a folder named "To Upload" that contains all the folders and files that you want to upload. In our example, it contains the following:
SubFolder1
SubFolder2
SubFolder3
File1
File2
Now, I'm guessing that your Excel file contains folders like the following:
site1
site2
site3
and you want to upload the files and folders in all these different folders.
However, here is the catch: the first time the job iterates, it changes the directory to "site1" and uploads the files and the folders. The second time, the active directory is site1 and the job tries to find a directory called site2 inside site1. If this is the case, the issue should be fixed by adding a "Change Working Directory" action just below the "Upload Folder to FTP" action (inside the loop) that will change the working directory to .. (2 periods). The 2 periods is a way to refer to the parent directory of the current one.
I hope that the description above helped you understand what is going on. Lemme know if you have any more questions!
Error is not blindness, error is cowardice
Error is not blindness, error is cowardice