【发布时间】:2012-08-05 07:13:26
【问题描述】:
这是 LIST ftp 的 cmd 的 sn-p:
count = file_list("./", &files);
if((fp_list = fopen("listfiles.txt", "w")) == NULL){
perror("Impossibile aprire il file per la scrittura LIST");
onexit(newsockd, sockd, 0, 2);
}
for(i=0; i < count; i++){
if(strcmp(files[i], "DIR ..") == 0 || strcmp(files[i], "DIR .") == 0) continue;
else{
fprintf(fp_list, "%s\n", files[i]);
}
}
fclose(fp_list);
if((fpl = open("listfiles.txt", O_RDONLY)) < 0){
perror("open file with open");
onexit(newsockd, sockd, 0, 2);
exit(1);
}
if(fstat(fpl, &fileStat) < 0){
perror("Errore fstat");
onexit(newsockd, sockd, fpl, 3);
}
fsize = fileStat.st_size;
if(send(newsockd, &fsize, sizeof(fsize), 0) < 0){
perror("Errore durante l'invio grande file list");
onexit(newsockd, sockd, fpl, 3);
}
rc_list = sendfile(newsockd, fpl, &offset_list, fileStat.st_size);
if(rc_list == -1){
perror("Invio file list non riuscito");
onexit(newsockd, sockd, fpl, 3);
}
if((uint32_t)rc_list != fsize){
fprintf(stderr, "Error: transfer incomplete: %d di %d bytes inviati\n", rc_list, (int)fileStat.st_size);
onexit(newsockd, sockd, fpl, 3);
}
printf("OK\n");
close(fpl);
if(remove( "listfiles.txt" ) == -1 ){
perror("errore cancellazione file");
onexit(newsockd, sockd, 0, 2);
}
&files 被声明为 char **files 并且函数 list_files 是我编写的与我的问题无关的函数。
我的问题:第一次LIST cmd 它被称为它可以正常工作,但如果我再次调用 LIST,它总是给我 “错误,传输不完整”我不明白为什么......
【问题讨论】:
-
从您在问题中发布的代码中是否看到“错误,传输不完整”消息?在那种情况下什么时候?否则,问题中的代码报告什么?
-
是的,这就是我在问题中发布的内容:) 当 sendfile 函数没有发送所有文件时,它会给我一个错误...
-
什么是
offset_list,你如何初始化它?请记住,如果sendfile无法发送所有内容,那么它将返回一个小于请求大小的值,您必须调整大小并重试。 -
offset_list 初始化为
offset_t...所以我必须这样做吗?send: if((uint32_t)rc_list != fsize){ fprintf(stderr, "Error: transfer incomplete: %d di %d bytes inviati\n", rc_list, (int)fileStat.st_size); goto send; }