suppaftp
suppaftp copied to clipboard
[BUG] - The file.log upload to ftp server. then lost \n line breaks
The Upload code of Core
fn test() {
let mut buffer = Vec::new();
let mut f = fs::File::open(src).unwrap();
let mut reader = f
.read_to_end(&mut buffer)
.map(|_| Cursor::new(buffer))
.map_err(FtpError::ConnectionError)?;
match upload_type {
StorageUploadType::Append => {
ftp.append_file(&fname, &mut reader)?;
}
StorageUploadType::Replace => {
ftp.put_file(&fname, &mut reader)?;
}
StorageUploadType::Once => {
if ftp.size(&fname).is_err() {
ftp.put_file(&fname, &mut reader)?;
} else {
/* 已经存在 */
}
}
};
}
I have found the problem, but please do not handle line breaks on different platforms; Adding the following code solves this problem; So I have the following proposal: for FPT uploads, we can increase the recognition of the FTP server platform; Then process the data; Secondly, increase the judgment of file types and only handle text types;
Let mut buffer=Vec:: new();
Let mut f=fs:: File:: open (src). unwrap();
Let mut reader=f
. readuto_end (&mut buffer)
. map (| _ |{
//Iterate over multiple references to each byte and replace '\ n' with '\ n'
//Use map to replace '\ n' with '\ n' and collect into a new Vec<u8>
Let modified_data: Vec<u8>=buffer
. iter()
. map (|&byte |{
If byte==b '\ n'{
Vec! [b '\ r', b '\ n']
}Else{
Vec! [byte]
}
})
. flatten()
. collect();
Cursor:: new (modified_data)
})
. map_err (FtpError: ConnectionError)?;