Scodigo, Inc.

Log In | Register

Cart Items:
0

Ftp upload file damage

I have just discovered an issue where .pdf files that I have been uploading via ftp with the new plugin are becoming damaged. I went back to the old plugin in just to verify and that is the case. Files uploaded with the older plugin are fine, new plugin damaged. I am doing the upload via a cf obtained at briandunning.com. Here is the cf:


// phpFTPUpload(localPath; remotePath; transferMode; host; user; password)
//
// Upload a file via FTP. Requires SmartPill PHP plugin.
//
// The file is always uploaded in PASSIVE mode. If you don't need this,
// comment out the call to ftp_pasv().
//
// trasnferMode should usually be 1 (FTP_BINARY); pass 0 for (FTP_ASCII).
//
// Returns:
// 1..n Successful copy (value indicates # of attempts to upload)
// -1 localPath doesn't resolve to a valid file/path
// -2 Couldn't log in to the FTP server
// -3 Couldn't copy the file to the FTP server
//
Let (
[
$localPath = localPath ;
$remotePath = remotePath ;
$transferMode = transferMode ;
$host = host ;
$user = user ;
$password = password ;

phpCode = "error_reporting(0); //(E_ALL & ~E_NOTICE);¶

$localPath = fm_evaluate('$localPath');¶
$remotePath = fm_evaluate('$remotePath');¶
$transferMode = fm_evaluate('$transferMode');¶
$host = fm_evaluate('$host');¶
$user = fm_evaluate('$user');¶
$password = fm_evaluate('$password');¶

// If you have timeouts trying to upload, increase $maxAttempts to a higher value.¶
$maxAttempts = 1;¶

$retVal = 0;¶
if (!file_exists($localPath))¶

$retVal = -1;¶

else¶

$connection = ftp_connect($host);¶

$login_result = @ftp_login($connection, $user, $password);¶
if ((!$connection) || (!$login_result))¶

$retVal = -2;¶

else¶

//ftp_pasv($connection, true);¶

$didUpload = false;¶
$numAttempts = 1;
while (!$didUpload && ($numAttempts <= $maxAttempts))¶

$didUpload = ftp_put($connection, $remotePath, $localPath, $transferMode);¶
if (!$didUpload)¶

$numAttempts++;¶


if ($didUpload)¶

$retVal = $numAttempts;¶

else¶

$retVal = -3;¶


ftp_close($connection);¶


echo $retVal;¶
"
] ;
PHP_Execute(phpCode)
)

I don't even know where to begin in troubleshooting this, any help would be greatly appreciated.

I am using Filemaker 9 Advanced on Win Vista Business Edition

Thank You

Bob

I'll take a look

Micah Woods's picture

Thanks Bob,

I'll take a look and see if I can reproduce this here and try to figure out what the problem is.

Regards,
Micah

something I just noticed.

something I just noticed. Prior to upgrading the plugin, the ave file size uploaded was ~179 KB. After the upgrade the ave file size is ~1 to 5 KB. So for some reason it is not uploading the whole file.

FTP_BINARY is now 2

Micah Woods's picture

Try executing this:

echo "FTP_BINARY: " . FTP_BINARY . "\nFTP_ASCII: " . FTP_ASCII;

I think you'll see that the FTP_BINARY constant is now 2 instead of 1. Simply change the trasferMode parameter from 1 to 2 and I think that will solve the problem.

Don't know why the constant value changed but this is a good reason to use constant names vs. values.

Regards,
Micah

Right On

Thanks for the response. I actually discovered this last night. I was working on a new script to upload the documents and was getting the same result. Then I noticed I had forgotten to change the ftp_put argument to FTP_BINARY. I never thought to just change the number :) I did get a working script out of the deal and learned a lot in the process! Thank you for the help and the wonderful product! I'll post my calculation in case some inexperienced person such as myself might be able to use it.

Let ( [

$fupload = VANTIVE::SO# & ".pdf";
$_expression = "

$file = 'C:\Database\Paperwork\\" & $fupload & "';¶
$remote_file = '/" & $fupload & "';¶¶

// set ftp vars¶
$ftp_server = 'ftp_server';¶
$ftp_user_name = 'username';¶
$ftp_user_pass = 'password';¶¶

// set up basic connection¶
$conn_id = ftp_connect($ftp_server);¶¶

// login with username and password¶
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);¶¶

// upload a file¶
if (ftp_put($conn_id, $remote_file, $file, FTP_BINARY)) {¶
echo 1;¶
} else {¶
echo -1;¶
}¶¶

// close the connection¶
ftp_close($conn_id);
"
];

PHP_Execute($_expression)

)