INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Connect to more than 1 sftp

Connect to more than 1 sftp

(OP)
I am trying to set up a system to pull data from more than 1 sftp site at timed intervals during the day.

I have found a piece of work that someone else did that does it from one, but I need to as I say from a second as well.

The code I have in the app config is this.

CODE --> c#

<appSettings>    
    <add key ="Extra1" value ="folder1/"/>
    <add key ="Extra2" value ="folder1/folder2/"/>
  </appSettings>

<sftp remoteHost="sftp.blah.blah.blah" port="22" username="user" password="password" rootPath ="/folder/folder/folder/folder/ "> </sftp> 

I then have this is a download manager

CODE

DirectoryInfo localRootInfo = new DirectoryInfo(ConfigurationManager.AppSettings["ToProcessFolder"].ToString());
            DirectoryInfo localSubRootInfo = localRootInfo.CreateSubdirectory(string.Format("{0:yyyyMMdd-HHmmss}", DateTime.Now));

            string Directory1 = ConfigurationManager.AppSettings["Extra1"];
            string Directory2 = ConfigurationManager.AppSettings["Extra2"];

            using (SftpManager sftp = new SftpManager())
            {
                // Loop through all of the folders and download if file available - NB These contain the WAV Files
                foreach (var directory in sftp.GetAllDirectories(sftp.RootDirectory))
                {
                    //string remoteWorkingFolder = string.Format("{0}{1}", sftp.RootDirectory, directory);
                    string subfolderName = Path.Combine(localSubRootInfo.FullName, directory.Name);
                    DirectoryInfo serviceLocalSubFolderInfo = new DirectoryInfo(subfolderName);

                    foreach (var file in sftp.GetAllFiles(directory.FullName))
                    {
                        if (!serviceLocalSubFolderInfo.Exists) serviceLocalSubFolderInfo.Create();

                        string localFilename = Path.Combine(serviceLocalSubFolderInfo.FullName, file.Name); 

what I want to do is add the Directory1 then Directory2 into the rootPath in order to do this, but nothing I do seems to work, it just fails, however, if I add the entire path into the rootPath then it works, so I know the connection is right, just the added bit is wrong.

'Clever boy...'

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close