Search code examples
coldfusionftpftps

coldfusion ftpsclient storefile


i am using ftpsclient for ftp file transfer , as it is explicit tls

here's the code i am using :

<cfscript>
ftpsClient = CreateObject("java","org.apache.commons.net.ftp.FTPSClient").init(JavaCast("boolean",false));

ftpsClient.connect(JavaCast("string","test.hostedftp.com"),21);
connected = ftpsClient.isConnected();

WriteOutput("Is Connected:" &  connected & '<br/>');

reply = ftpsClient.getReplyCode();
WriteOutput("Is reply:" &  reply & '<br/>');

login = ftpsClient.login('test','test');
WriteOutput("Is Logged in:" &  login & '<br/>');

    ftpsClient.enterLocalPassiveMode();
    ftpsClient.changeWorkingDirectory("/test");
    reply = ftpsClient.getReplyCode();
    WriteOutput("Is changeWorkingDirectory:" &  reply & '<br/>');


</cfscript>


<cfset fileStream = CreateObject(
            "java",
            "java.io.FileInputStream"
            ).Init(
                CreateObject(
                    "java",
                    "java.io.File"
                    ).Init(
                        "C:\Users\test\test.txt"
                        )
            ) />
                <cfset storefile = ftpsClient.storeFile("LocalFile.txt", fileStream)>
                <cfset replycode = ftpsClient.getReplyCode()>
                <cfoutput>#replycode#</cfoutput><br>
                <cfset fileStream.close()>
                <cfoutput>#storefile#</cfoutput>

But its not uploading the file here' the output :

Is Connected:YES
Is reply:234
Is Logged in:YES
Is changeWorkingDirectory:250
500
NO 

which means after storefie replycode is coming out to be "500".

I dont know what's wrong in the code, if anybody can help.

Thanks in advance!


Solution

  • Try executing the PROT command. You can put it after the enterLocalPassiveMode() line

    ftpsClient.execPROT("P");
    

    I was able to get it to work in my local testing this way.

    PROT deals with Data Protection Level. If one isnt supplied, it sends it as Clear. P stands for Private. Im guessing it is transferring the file not securely.

    What does the getReplyString() display? Does it say anything about the Data channel not being secure?