Feature request: Upload temp file and rename to original

Moderator: Project members

Post Reply
Message
Author
Wiliam
500 Command not understood
Posts: 4
Joined: 2010-01-24 19:48
First name: Wiliam
Last name: W

Feature request: Upload temp file and rename to original

#1 Post by Wiliam » 2010-01-24 20:15

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.

User avatar
botg
Site Admin
Posts: 33238
Joined: 2004-02-23 20:49
First name: Tim
Last name: Kosse
Contact:

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

#2 Post by botg » 2010-01-24 22:03

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.

Wiliam
500 Command not understood
Posts: 4
Joined: 2010-01-24 19:48
First name: Wiliam
Last name: W

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

#3 Post by Wiliam » 2010-01-24 22:05

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? :(

User avatar
botg
Site Admin
Posts: 33238
Joined: 2004-02-23 20:49
First name: Tim
Last name: Kosse
Contact:

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

#4 Post by botg » 2010-01-24 22:43

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.

Wiliam
500 Command not understood
Posts: 4
Joined: 2010-01-24 19:48
First name: Wiliam
Last name: W

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

#5 Post by Wiliam » 2010-01-24 22:50

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!

User avatar
boco
Contributor
Posts: 25330
Joined: 2006-05-01 03:28
Location: Germany

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

#6 Post by boco » 2010-01-25 13:30

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.
### BEGIN SIGNATURE BLOCK ###
No support requests per PM! You will NOT get any reply!!!
FTP connection problems? Do yourself a favor and read Network Configuration.
FileZilla connection test: https://filezilla-project.org/conntest.php
### END SIGNATURE BLOCK ###

Wiliam
500 Command not understood
Posts: 4
Joined: 2010-01-24 19:48
First name: Wiliam
Last name: W

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

#7 Post by Wiliam » 2010-01-25 14:42

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.

User avatar
botg
Site Admin
Posts: 33238
Joined: 2004-02-23 20:49
First name: Tim
Last name: Kosse
Contact:

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

#8 Post by botg » 2010-01-25 18:46

Yes, almost. You need to enclose the string literal in _T() though so that it works with the mandatory unicode build of FileZilla.

Post Reply