Now I can log on to the FTP Server whats the COBOL code to send a small text file.
Thanks
Neil.
I haven't used the .NET Framework's FtpWebRequest class, which is what you're using, according to your previous question. But from the Microsoft documentation, it looks like the general procedure for any FTP operation using that class is:
Open the FTP connection, specifying the name of the target file in the URL. In your previous note, you used "ftp://ftp.TestSite.com" as the URL. You'll want to use something like ftp://ftp.TestSite.com/somefile.txt.
Set the Method property to indicate what operation you'd like to perform. In this case that's UploadFile.
set cFtpWebRequest::Method to type WebRequestMethods::Ftp::UploadFile
Get the RequestStream property. This will send a command to the FTP server and create the data connection. (The FTP protocol uses two network connections between the client and server, one for control and one for data.) It will return a network stream for the data connection.
set requestStream to cFtpWebRequest::RequestStream
Write the file contents to the request stream.
invoke fileStream::CopyTo(requestStream)
Close the request stream.
invoke requestStream::Close
Invoke the GetResponse method. This gets the response from the FTP server, which you can check to see if the operation succeeded.
Now I can log on to the FTP Server whats the COBOL code to send a small text file.
Thanks
Neil.
The following works with .NET Framework 3.5 if you must use it:
$set ilusing"System.Net" $set ilusing"System.IO" program-id. Program1 as "testftp.Program1". data division. working-storage section. 01 cFtpWebRequest type System.Net.FtpWebRequest. 01 cFtpWebResponse type System.Net.FtpWebResponse. 01 cFileInfo type FileInfo. 01 fileContents type Byte occurs any. 01 cFileStream type FileStream. 01 writer type Stream. procedure division. try set cftpWebRequest to type FtpWebRequest::Create(new type Uri("ftp.microfocus.com/testfile.txt")) as type FtpWebRequest set cFtpWebRequest::Method to type "System.Net.WebRequestMethods Ftp"::"UploadFile" set cftpWebRequest::Proxy to null set cftpWebRequest::UseBinary to true set cftpWebRequest::Credentials to new NetworkCredential("user", "password") set cFileInfo to new FileInfo("c:\\\\temp\\\\testfile.txt") *>e.g.: c:\\\\Test.txt set size of fileContents to cFileInfo::Length set cFileStream to cFileInfo::OpenRead invoke cFileStream::Read(fileContents, 0, type Convert::ToInt32(cFileInfo::Length)) set writer to cftpWebRequest::GetRequestStream invoke writer::Write(fileContents, 0, fileContents::Length) invoke writer::Close set cftpWebResponse to cFtpWebRequest::GetResponse as type FtpWebResponse display cftpWebResponse::StatusDescription catch ex as type WebException display ex::Message end-try goback.
Now I can log on to the FTP Server whats the COBOL code to send a small text file.
Thanks
Neil.
I see that with assistance from Chris you have this working now. I just wanted to point out that my sample code was COBOL - I was using the syntax supported by the current Visual COBOL, including unquoted method names (though some of your changes might be necessary there too; I hadn't compiled the sample code). And, as noted elsewhere in the thread, the Stream::CopyTo method is available in .NET Framework 4. Mentioning what version of Visual COBOL and .NET Framework you're using when you post a question can help avoid some confusion.