Hi,
AX D365 FTP Interface with Third Party System - Part 5 - Delete and Move FTP File to Archive Folder
Below code for Delete the file in FTP
Public void ftpDeleteFile(str ftpHostandFolder,str fileName)
{
// Marshaling .NET to X++
ftpObject = System.Net.WebRequest::Create(ftpHostandFolder + fileName);
ftpWebRequestDel = ftpObject;
if (ftpWebRequestDel)
{
ftpWebRequestDel.set_Method('DELE');
credential = new System.Net.NetworkCredential(FTPUserName,FTPPassword);
ftpWebRequestDel.set_Credentials(credential);
response = ftpWebRequestDel.GetResponse();
ftpWebResponseDel = ftpWebRequestDel.GetResponse();
if (ftpWebResponseDel)
{
info(strFmt("Successfully Deleted",fileName));
}
}
}
Below code for Move file from source folder to destination folder in FTP
Public void MoveFiletoArchiveFolder(str sourcefileNamePath,str ftpHostandArchiveFolder,str strFileName)
{
System.IO.Stream requestStream;
System.Byte[] bytes;
System.IO.Stream readStream;
System.Text.Encoding utf8;
System.Exception netExcepn;
str retVal;
ftpHostandArchiveFolder += strFileName; //Here Provide Full FTP Path
InteropPermission permI = new InteropPermission(InteropKind::ClrInterop);
FileIOPermission permIO = new FileIOPermission(ftpHostandArchiveFolder,'w');
Set permissionSet = new Set(Types::Class);
new InteropPermission(InteropKind::ClrInterop).assert();
// Read file
reader = new System.IO.StreamReader(sourcefileNamePath); //Path for read file
utf8 = System.Text.Encoding::get_UTF8();
bytes = utf8.GetBytes( reader.ReadToEnd() );
reader.Close();
//Create File in FTP
ftpo = System.Net.WebRequest::Create(ftpHostandArchiveFolder);
request = ftpo;
credential = new System.Net.NetworkCredential(FTPUserName,FTPPassword);
request.set_Credentials(credential);
request.set_ContentLength(bytes.get_Length());
//response = request.GetResponse();
////FTP file UploadFile represents STOR
///FTP file UploadFileWithUniqueName represents STOU
request.set_Method('STOR');
requestStream = request.GetRequestStream();
requestStream.Write(bytes,0,bytes.get_Length());
requestStream.Close();
ftpResponse = request.GetResponse();
response = ftpResponse;
}
AX D365 FTP Interface with Third Party System - Part 5 - Delete and Move FTP File to Archive Folder
Below code for Delete the file in FTP
Public void ftpDeleteFile(str ftpHostandFolder,str fileName)
{
// Marshaling .NET to X++
ftpObject = System.Net.WebRequest::Create(ftpHostandFolder + fileName);
ftpWebRequestDel = ftpObject;
if (ftpWebRequestDel)
{
ftpWebRequestDel.set_Method('DELE');
credential = new System.Net.NetworkCredential(FTPUserName,FTPPassword);
ftpWebRequestDel.set_Credentials(credential);
response = ftpWebRequestDel.GetResponse();
ftpWebResponseDel = ftpWebRequestDel.GetResponse();
if (ftpWebResponseDel)
{
info(strFmt("Successfully Deleted",fileName));
}
}
}
Below code for Move file from source folder to destination folder in FTP
Public void MoveFiletoArchiveFolder(str sourcefileNamePath,str ftpHostandArchiveFolder,str strFileName)
{
System.IO.Stream requestStream;
System.Byte[] bytes;
System.IO.Stream readStream;
System.Text.Encoding utf8;
System.Exception netExcepn;
str retVal;
ftpHostandArchiveFolder += strFileName; //Here Provide Full FTP Path
InteropPermission permI = new InteropPermission(InteropKind::ClrInterop);
FileIOPermission permIO = new FileIOPermission(ftpHostandArchiveFolder,'w');
Set permissionSet = new Set(Types::Class);
new InteropPermission(InteropKind::ClrInterop).assert();
// Read file
reader = new System.IO.StreamReader(sourcefileNamePath); //Path for read file
utf8 = System.Text.Encoding::get_UTF8();
bytes = utf8.GetBytes( reader.ReadToEnd() );
reader.Close();
//Create File in FTP
ftpo = System.Net.WebRequest::Create(ftpHostandArchiveFolder);
request = ftpo;
credential = new System.Net.NetworkCredential(FTPUserName,FTPPassword);
request.set_Credentials(credential);
request.set_ContentLength(bytes.get_Length());
//response = request.GetResponse();
////FTP file UploadFile represents STOR
///FTP file UploadFileWithUniqueName represents STOU
request.set_Method('STOR');
requestStream = request.GetRequestStream();
requestStream.Write(bytes,0,bytes.get_Length());
requestStream.Close();
ftpResponse = request.GetResponse();
response = ftpResponse;
}
Comments
Post a Comment