Skip to main content

Notifications

Dynamics 365 Community / Forums / Finance forum / Getting error while to...
Finance forum
Suggested answer

Getting error while to make SFTP Connection for file sharing.

editSubscribe (2) ShareShare
ReportReport
Posted on by 8
Getting error while to make SFTP Connection for file sharing.
 
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond at Renci.SshNet.Abstractions.SocketAbstraction.Connect(IPEndPoint remoteEndpoint, TimeSpan connectTimeout) at Renci.SshNet.Session.SocketConnect(String host, Int32 port) at Renci.SshNet.Session.Connect() at Renci.SshNet.BaseClient.Connect().
 
Thanks in Advance.
  • Mohamed Amine Mahmoudi Profile Picture
    Mohamed Amine Mahmoudi 4,311 User Group Leader on at
    Getting error while to make SFTP Connection for file sharing.
    Hi,
     
    I think the problem is due to connection elements (username, port, SSH key) !
    port 22 is generally used for SFTP.
     
    Best regards,
    Mohamed Amine MAHMOUDI
  • CU29041319-0 Profile Picture
    CU29041319-0 8 on at
    Getting error while to make SFTP Connection for file sharing.
    HI Amine and Layan, I just used the below code (DLL) for SFTP Connection,
    While Debugging I found that the Exception in the Yellow marked line Below, I have Created SFTP connection in my local server and SFTP Connection is Connected via fileZilla, May I know Whether it is Coding mistake or SFTP Setup Mistake.
     
    using System;
    using System.IO;
    using System.Net;
    using System.Collections.Generic;
    using Renci.SshNet;
    using System.Text;

    namespace CIT_SFTPConnnect
    {
        public class ConnectorClass
        {
            public static string uploadSFTPFile(string host,string username,string password,System.IO.Stream sourceFile,string destinationPath,int port,string fileName,string privateKeyFilePath = "")
            {
                string successStr = "Fail";
                List<AuthenticationMethod> methods;
                /*It depends if the private key file is present for authentication. If the SFTP is key secured then the private key file has to be passed.*/
                if (privateKeyFilePath != "")
                {
                  var privateKeyFile = new PrivateKeyFile(privateKeyFilePath);
                  methods = new List<AuthenticationMethod>
                {
                    new PasswordAuthenticationMethod(username, password),
                    new PrivateKeyAuthenticationMethod(username, privateKeyFile)
                };
                            }
                else
                {
                                methods = new List<AuthenticationMethod>
                {
                    new PasswordAuthenticationMethod(username, password)
                };
                }
                try
                {
                    var connectionInfo = new ConnectionInfo(host, port, username, methods.ToArray());
                    using (SftpClient sftpclient = new SftpClient(connectionInfo))
                    {
                        sftpclient.Connect();
                        sftpclient.ChangeDirectory(destinationPath.Trim());
                        sourceFile.Position = 0;
                        sftpclient.BufferSize = 8 * 1024;
                        sftpclient.UploadFile(sourceFile, fileName);
                    }
                    successStr = "Pass";
                }
                catch (WebException e)
                {
                    successStr =  "Fail"+e;
                }
                return successStr;
            }
        }
    }
     
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    Mohamed Amine Mahmoudi 4,311 User Group Leader on at
    Getting error while to make SFTP Connection for file sharing.
    Hi,
     
    Can you please share with us more details.
     
    Mohamed Amine MAHMOUDI
  • Layan Jwei Profile Picture
    Layan Jwei 3,079 Super User on at
    Getting error while to make SFTP Connection for file sharing.
    Hi,

    Can you share with us the code please and provide more details to help

Helpful resources

Quick Links

Take the Community feedback survey!

Answer this brief 15-question survey about your Community experience…

Demystifying Copilot: Service Edition with Sundar Raghavan

Sundar answers more questions about Copilot for Service...

Dynamics 365 Business Central vs Finance and SCM

Take a look at the key differences between Business Central and…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,375 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 223,308 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,140

Featured topics

Product updates

Dynamics 365 release plans