Page 1 of 1

Feature request: Upload temp file and rename to original

Posted: 2010-01-24 20:15
by Wiliam
Hi, I only entered to say that web developers need to upload web files without overwriting any file when uploading, only when completed.

For example if the upload fails, the file in the server will be corrupt, or when you are uploading the file it cant be used, if it is a php file then throws errors to users that are using it.

The solution would be upload a temp file and then rename it. I remember that previous versions of filezilla used this method to upload files.

Wiliam.

Re: Feature request: Upload temp file and rename to original

Posted: 2010-01-24 22:03
by botg
I remember that previous versions of filezilla used this method to upload files.
Odd, I wrote FileZilla and don't remember implementing anything like this. Then again, I might be confusing things.

Re: Feature request: Upload temp file and rename to original

Posted: 2010-01-24 22:05
by Wiliam
botg wrote:
I remember that previous versions of filezilla used this method to upload files.
Odd, I wrote FileZilla and don't remember implementing anything like this. Then again, I might be confusing things.
Then I confused it, sorry. You understood what I said? :(

Re: Feature request: Upload temp file and rename to original

Posted: 2010-01-24 22:43
by botg
Yes. Would be hard to implement though as the exact semantics of the RNFR/RNTO command pair are left somewhat unspecified by the FTP standard.

Re: Feature request: Upload temp file and rename to original

Posted: 2010-01-24 22:50
by Wiliam
botg wrote:Yes. Would be hard to implement though as the exact semantics of the RNFR/RNTO command pair are left somewhat unspecified by the FTP standard.
But it will be enough for example to do the next automatically:

Source file to upload: code.php
Existing file in the server: code.php (old one)

STOR .code.php.tmp (first dot to make it invisible)
RNFR .code.php.tmp
RNTO code.php (change old one to new one instantaneously, without corrupting the file when uploading)

I think that I haven't understood what you said about that two ftp commands. Sorry!

Re: Feature request: Upload temp file and rename to original

Posted: 2010-01-25 13:30
by boco
Certainly possible, but some servers won't like it. On many servers, you can't RNTO a file that exists, so you'd need to DELE the target file first. So an possibly implemented method would only work with full rights on the target directory.

Re: Feature request: Upload temp file and rename to original

Posted: 2010-01-25 14:42
by Wiliam
In my case it will be ok because the folders have full privileges and RNTO can overwrite. I'm only searching a fast way to hook filezilla and work faster in my webprojects, for example I can try to hook this region of code to upload the file with another name:

[ftpcontrolsocket.cpp - line 2718]

Code: Select all

if (pData->download)
	cmd = _T("RETR ");
else if (pData->resume)
{
	if (CServerCapabilities::GetCapability(*m_pCurrentServer, rest_stream) == yes)
		cmd = _T("STOR "); // In this case REST gets sent since resume offset was set earlier
	else
	{
		wxASSERT(pData->resumeOffset == 0);
		cmd = _T("APPE ");
	}
}
else
	cmd = _T("STOR ");
	
// Hook

if(!pData->download && !pData->resume && pData.remoteFile.Length > 4 && pData.remoteFile.Mid(pData.remoteFile.Length - 4).Lower() == ".php")
	cmd += pData->remotePath.FormatFilename(pData->remoteFile + ".tmp", !pData->tryAbsolutePath);
else
	cmd += pData->remotePath.FormatFilename(pData->remoteFile, !pData->tryAbsolutePath);
This will upload the file with the name (name + ".tmp")? Sorry if it's incorrect, I haven't used C++ since 5 or 6 years, and wx never.

Re: Feature request: Upload temp file and rename to original

Posted: 2010-01-25 18:46
by botg
Yes, almost. You need to enclose the string literal in _T() though so that it works with the mandatory unicode build of FileZilla.