web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Upload File to FTP Error

(0) ShareShare
ReportReport
Posted on by 1,214

Hi,

i was referring this article to write a file into FTP server. I run the logic from a button clicked method in a custom form.

From original code in the article, I only changed the ftp server and file name. Here's my code:

public void clicked()
{
    TextStreamIo textStreamIO = TextStreamIo::constructForWrite();
    System.Text.Encoding getUTF8;
    System.IO.StreamReader streamReader;
    System.Byte[] bytes;
    System.Object request,response,credential;
    System.Net.FtpWebRequest ftpRequest;
    //System.Net.IWebProxy;
    System.IO.Stream requestStream;
    System.Net.FtpWebResponse ftpResponse;
    Str1260 ftpFileName = "ftp://ftp.dlptest.com"   @"/"   "hairulFileName.txt";
    System.IO.StreamReader reader;
    System.Char[] chars;
    container con;
    System.IO.Stream stream;
    ;


    textStreamIO.writeExp(['Started']);
    textStreamIO.writeExp(['This Is Test', ' For Barcode']);
    textStreamIO.writeExp(['End']);

    stream = textStreamIO.getStream();
    stream.Position = 0;
    reader = new System.IO.StreamReader(stream);
    getUTF8 = System.Text.Encoding::get_UTF8();
    bytes = getUTF8.GetBytes(reader.ReadToEnd());
    request = System.Net.WebRequest::Create(new System.Uri(ftpFileName));
    ftpRequest = request;
    credential = new System.Net.NetworkCredential("dlpuser", "rNrKYTX9g7z3RgJRmxWuGHbeu");
    ftpRequest.set_Credentials(credential);
    ftpRequest.set_ContentLength(bytes.get_Length());
    ftpRequest.set_Method("STOR");
    ftpRequest.set_Proxy(null);
    requestStream = ftpRequest.GetRequestStream();
    requestStream.Write(bytes,0,bytes.get_Length());
    requestStream.Close();
    response = ftpRequest.GetResponse();
    ftpResponse = response;
    info('Processed.');
}

However, when building the code, I get Reference error like following:

webproxy.png

How can i resolve this reference? Thank you.

I have the same question (0)
  • Kamil Gwiazdowski Profile Picture
    35 on at
    RE: Upload File to FTP Error

    Hi,

    I think it won't work on self-service environments (T2+).

    Refering this docs and conversation with MS engineer FTP communication is not supported starting from T2 environment type. In our project we cannot establish communication from self-service to remote on-premise FTP.

  • Martin Dráb Profile Picture
    235,968 Most Valuable Professional on at
    RE: Upload File to FTP Error

    All right, so we can ignore all the other code; this single line is all what's needed.

    No, I don't think you should add any references. On the contrary, I asked if you didn't add any before, because the error message complains about finding this type in multiple assemblies.

    I can declare System.NetIWebProxy variable without any problem; something seems to be wrong with your development environment.

    If I check the version of System.Net.Http.Primitives in the bin folder of my F&O environment, it's 4.2.22.0. Your error message suggests that you has the version 1.5.0.0 somewhere, which looks wrong to me.

  • HAIRUL HAZRI Profile Picture
    1,214 on at
    RE: Upload File to FTP Error

    Hi Martin,

    System.Net.IWebProxy is not recognized. I tried to add .Net reference but could not find it. How else can I add the reference?

    iwebproxy-not-found.png

    This is cloud hosted DEV environment on version 10.0.17 PU41, if that helps.

  • Martin Dráb Profile Picture
    235,968 Most Valuable Professional on at
    RE: Upload File to FTP Error

    Did you add any refences to .NET assemblies?

    What if you try just the following code?

    System.Net.IWebProxy test;

    Does it fail as well?

    By the way, you should place your code to a class method with an intent-revealing name, instead of doing everyhing in clicked() method of the form.

  • HAIRUL HAZRI Profile Picture
    1,214 on at
    RE: Upload File to FTP Error

    Hi Will,

    I created the Visual Studio Project with .Net Framework 4.6.1.

  • WillWU Profile Picture
    22,361 on at
    RE: Upload File to FTP Error

    Hi HAIRUL HAZRI,

    What is the version of your .net?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 878 User Group Leader

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 681 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 496 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans